const express = require('express');
const router = express.Router();
const cartController = require('../controllers/cart.controller');
const { authMiddleware } = require('../middlewares/auth.middleware');

// 所有购物车路由都需要身份验证
router.use(authMiddleware);

// 获取用户购物车
// GET /api/cart
router.get('/', cartController.getCart);

// 获取购物车商品数量（用于徽章显示）
// GET /api/cart/count
router.get('/count', cartController.getCartItemCount);

// 添加商品到购物车
// POST /api/cart
// Body: { productId, quantity, selectedSpecs }
router.post('/', cartController.addToCart);

// 更新购物车商品数量
// PUT /api/cart/items/:itemId
// Body: { quantity }
router.put('/items/:itemId', cartController.updateCartItem);

// 从购物车移除商品
// DELETE /api/cart/items/:itemId
router.delete('/items/:itemId', cartController.removeFromCart);

// 清空购物车
// DELETE /api/cart
router.delete('/', cartController.clearCart);

module.exports = router;
